<?php
/*
    GUMUD is Extensible Web-based Multi-User Dungeon Software.

    Copyright (C) 2013  White Rabbit

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
function parserCommandDecode ($itx,$commandstring) {
	$commandstring = trim($commandstring);
	$fooarray= explode(" ",$commandstring);
	$foonummax = getSNumArr($fooarray);
	$x = 1;
	$commandstring2 = "";
	$output = "";
	
	$commandstring2 = trim($commandstring);
	if (($commandstring2 == "who is here") or ($commandstring2 == "who is around") or ($commandstring2 == "who is in this area") or ($commandstring2 == "who is in this room")) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][6] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getHeartbeatUsers&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$array3 = splitData($itx['com-inner'][6]);
		writeResponseFile($itx['com-inner'][3], "<p>Area Inhabitants:".$array3[2]);
	}
	elseif ($commandstring2 == "move north") {
	
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		if (file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=verifyLocalCoordinates&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".((int)$array2[1]+1)) == "validated") {
			file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=putLocalLoc&uuid=".$itx['com-inner'][3]."&localX=".$array2[0]."&localY=".((int)$array2[1]+1));
			$output = "<p>Scene: You have moved north.";
			writeResponseFile($itx['com-inner'][3], $output);

		
		}
		else {
			$output = "<p>Scene: You cannot move north.";
			writeResponseFile($itx['com-inner'][3], $output);
		}
		
		
	}
	elseif (($commandstring2 == "who is here") or ($commandstring2 == "who is around") or ($commandstring2 == "who is in this area") or ($commandstring2 == "who is in this room")) {
		$itx['com-inner'][6] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getHeartbeatUsers&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$array3 = splitData($itx['com-inner'][6]);
		writeResponseFile($itx['com-inner'][3], "<p>Area Inhabitants:".$array3[2]);
	}
	elseif ($commandstring2 == "move south") {
	
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		if (file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=verifyLocalCoordinates&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".((int)$array2[1]-1)) == "validated") {
			file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=putLocalLoc&uuid=".$itx['com-inner'][3]."&localX=".$array2[0]."&localY=".((int)$array2[1]-1));
			$output = "<p>Scene: You have moved south.";
			writeResponseFile($itx['com-inner'][3], $output);

		
		}
		else {
			$output = "<p>Scene: You cannot move south.";
			writeResponseFile($itx['com-inner'][3], $output);
		}
		
		
	}
	elseif ($commandstring2 == "move west") {
	
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		if (file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=verifyLocalCoordinates&uuid=".$itx['com-inner'][4]."&localX=".((int)$array2[0]-1)."&localY=".$array2[1]) == "validated") {
			file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=putLocalLoc&uuid=".$itx['com-inner'][3]."&localX=".((int)$array2[0]-1)."&localY=".$array2[1]);
			$output = "<p>Scene: You have moved west.";
			writeResponseFile($itx['com-inner'][3], $output);

		
		}
		else {
			$output = "<p>Scene: You cannot move west.";
			writeResponseFile($itx['com-inner'][3], $output);
		}
		
		
	}
	elseif ($commandstring2 == "move east") {
	
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		if (file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=verifyLocalCoordinates&uuid=".$itx['com-inner'][4]."&localX=".((int)$array2[0]+1)."&localY=".$array2[1]) == "validated") {
			file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=putLocalLoc&uuid=".$itx['com-inner'][3]."&localX=".((int)$array2[0]+1)."&localY=".$array2[1]);
			$output = "<p>Scene: You have moved east.";
			writeResponseFile($itx['com-inner'][3], $output);

		
		}
		else {
			$output = "<p>Scene: You cannot move east.";
			writeResponseFile($itx['com-inner'][3], $output);
		}
		
	}
	
	elseif (($commandstring2 == "look around") or ($commandstring2 == "look") or ($commandstring2 == "look at surroundings") or ($commandstring2 == "look at area")  or ($commandstring2 == "look at scene")) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$itx['com-inner'][6] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getHeartbeatUsers&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$array3 = splitData($itx['com-inner'][6]);
		$output = "<p>Scene: You see ".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=sceneViewRequest&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&personuuid=".$itx['com-inner'][3]);
		writeResponseFile($itx['com-inner'][3], $output." ".$array3[1]);
	}
	elseif (($commandstring2 == "look at self") or ($commandstring2 == "look at myself") or ($commandstring2 == "look at me") or ($commandstring2 == "look at my avatar")) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		
		$output = "<p>Appearance: While looking at yourself you see a ".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=viewAvatar&uuid=".$itx['com-inner'][3]);
		writeResponseFile($itx['com-inner'][3], $output);
	}
	elseif (($commandstring2 == "look closely at self") or ($commandstring2 == "look closely at myself") or ($commandstring2 == "look closely at me") or ($commandstring2 == "look closely at my avatar")) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		
		$output = "<p>Appearance: While looking closely at yourself you see a ".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=viewAvatarDetail&uuid=".$itx['com-inner'][3]);
		writeResponseFile($itx['com-inner'][3], $output);
	}
	elseif (($commandstring2 == "clear screen") or ($commandstring2 == "cls")) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		
		clearResponseFile($itx['com-inner'][3], "<p>Screen: Cleared Succesfully.");
	}
	elseif (($commandstring2 == "look closely around") or ($commandstring2 == "look closely") or ($commandstring2 == "look closely at surroundings") or ($commandstring2 == "look closely at area")  or ($commandstring2 == "look closely at scene")) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$itx['com-inner'][6] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getHeartbeatUsers&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$array3 = splitData($itx['com-inner'][6]);
		$output = "<p>Scene: You see ".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=sceneDetailViewRequest&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&personuuid=".$itx['com-inner'][3]);
		writeResponseFile($itx['com-inner'][3], $output." ".$array3[2]);
	}
	elseif (preg_match("/(set my|change my|edit my|set avatar|change avatar|edit avatar)+(\p{Zs}|\040)+(description|view)+(\p{Zs}|\040)+(using view)+(\p{Zs}|\040)+(\w)+(\p{Zs}|\040)+(using type)+(\p{Zs}|\040)+(stateViewSuccess|stateViewFailure|stateDetailViewSuccess|stateDetailViewFailure)+(\p{Zs}|\040)+(with value)+(\p{Zs}|\040)+(\w|\W)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$arrayS = explode(" with value ",$commandstring2);
		$array3 = explode(" using type ",$arrayS[0]);
		$array4 = explode(" using view ",$array3[0]);
		$output = "<p>Appearance: ".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=editAvatarLex&uuid=".$itx['com-inner'][3]."&data=".urlencode($arrayS[1])."&state=".$array4[1]."&field=".$array3[1]);
	writeResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(delete|remove|kill)+(\p{Zs}|\040)+(object|item)*(\p{Zs}|\040)*(from scene|in scene|from scene)+(\p{Zs}|\040)+(\w|\p{Zs}|\040)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		
		$str1 = preg_replace("/(delete|remove|kill)+(\p{Zs}|\040)+(object|item)*(\p{Zs}|\040)*(from scene|in scene|from scene)+(\p{Zs}|\040)+/","",$commandstring2);
		$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=deleteObject&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&editor=".$itx['com-inner'][3]."&object=".urlencode($str1))."</span>";
	writeResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(give|transfer|give away|share)+(\p{Zs}|\040)+(\p{Zs}|\040|\w|\d)+(with|to)+(\p{Zs}|\040)+(\p{Zs}|\040|\w|\d)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		if (preg_match("/(give|transfer|give away|share)+(\p{Zs}|\040)+(\p{Zs}|\040|\w|\d)+(with)+(\p{Zs}|\040)+(\p{Zs}|\040|\w|\d)+/",$commandstring2)) {
		$array1 = explode("with ",$commandstring2);
		}
		else {
		$array1 = explode("to ",$commandstring2);
		}
		
		$array2 = explode(" ",$array1[1]);
		
		$str1 = preg_replace("/(give|transfer|give away|share)+(\p{Zs}|\040)+/","",$array1[0]);
		$str2 = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$array2[0]."&lastname=".$array2[1]);
		
		$output = "<p>Inventory Transfer: ".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=giveObject&uuid=".$itx['com-inner'][3]."&touuid=".$str2."&object=".urlencode($str1));
	writeResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(create region|make region)+(\p{Zs}|\040)+(\p{Zs}|\040|\w|\d)+(:)+(\d)+(:)+(\d)+/",$commandstring2)) {
	$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
	$str1 = preg_replace("/(create region|make region)+(\p{Zs}|\040)+/","",$commandstring2);
	$array1 = explode(":",$str1);
	$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=createRegion&uuid=".$itx['com-inner'][3]."&data=".urlencode($array1[0])."&regionX=".$array1[1]."&regionY=".$array1[2]);
	writeResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(set view|set view to|set area view|set area view to|set scene|set area|set scene view|set scene view to)+(\p{Zs}|\040)+(using view)+(\p{Zs}|\040)+(\w)+(\p{Zs}|\040)+(using type)+(\p{Zs}|\040)+(\w)+(\p{Zs}|\040)+(with value)+(\p{Zs}|\040)+(\w|\W)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$explode1 = explode(" with value ",$commandstring2);
		$var1 = $explode1[1];
		$typearray = explode(" using type ",$explode1[0]);
		$type = $typearray[1];
		$viewarray = explode(" using view ",$typearray[0]);
		$view = $viewarray[1];
		$var2 = urlencode(strip_tags($var1));
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=setViewRequest&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&data=".$var2."&editor=".$itx['com-inner'][3]."&view=".$view."&type=".$type)."</span>";
		writeResponseFile($itx['com-inner'][3], $output);
	}
	// DEPRECATED
	/*
	elseif (preg_match("/(set detail view:|set detail view to:|set area detail view:|set area detail view to:|set scene detail:|set area detail:|set scene detail view:|set scene detail view to:)+(\w|\W)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$var1 = preg_replace("/(set detail view:|set detail view to:|set area detail view:|set area detail view to:|set scene detail:|set area detail:|set scene detail view:|set scene detail view to:)+/","",$commandstring2);
		$var2 = urlencode(strip_tags($var1));
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=setViewDetailRequest&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&data=".$var2."&editor=".$itx['com-inner'][3])."</span>";
		writeResponseFile($itx['com-inner'][3], $output);
	}
	*/
	elseif (preg_match("/(teleport to|beam to|move current region to|move my current region to)+(\p{Zs}|\040)+(\p{Zs}|\040|\w|\d)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$var1 = preg_replace("/(teleport to|beam to|move current region to|move my current region to)+(\p{Zs}|\040)+/","",$commandstring2);
		$output = "<p><span class='locmovecommand'>Teleport:</span> <span class='locamoveentry'>".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=teleportAvatar&uuid=".$itx['com-inner'][3]."&data=".$var1)."</span>";
	writeResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(create area|create scene|create new area|create new scene|create new area to|create new scene to|create new area to the|create new scene to the)+(\p{Zs}|\040)+(north|south|east|west)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$var1 = preg_replace("/(create area|create scene|create new area|create new scene|create new area to|create new scene to|create new area to the|create new scene to the)+(\p{Zs}|\040)+/","",$commandstring2);
		$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=createArea&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&data=".$var2."&editor=".$itx['com-inner'][3]."&direction=".$var1)."</span>";
	writeResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(look closely at|examine closely)+(\p{Zs}|\040)+(\w|\p{Zs}|\040)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$var1 = preg_replace("/(look closely at|examine closely)+(\p{Zs}|\040)+/","",$commandstring2);
		$array3 = explode(" ",$var1);
		
		if((!isset($array3[2])) and (isset($array3[1]))) {
		$itx['com-inner'][6] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$array3[0]."&lastname=".$array3[1]);
		if ($itx['com-inner'][6] != "fail") {
		$itx['com-inner'][7] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][6]);
		$itx['com-inner'][8] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][7]);
		$array4 = splitData($itx['com-inner'][8]);
		$array5 = splitData(file_get_contents("http://".$array4[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][6]));
			if(($array5[0] == $array2[0]) and ($array5[1] == $array2[1])) {
			
			$itx['com-inner'][9] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getHeartbeat&uuid=".$itx['com-inner'][6]);
				if($itx['com-inner'][9] > (time() - 100)) {
				$output = "<p>Appearance: You see a ".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=viewAvatar&uuid=".$itx['com-inner'][6]);
				}
				else {
				$output = "<p>Scene: You don't see ".$array3[0]." ".$array3[1]." here at this time.";
				}
			}
			else {
				$output = "<p>Scene: You don't see ".$array3[0]." ".$array3[1]." here at this time.";
			}
		}
		else {
		$output = "<p>Inspection View: ".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=viewObjectDetail&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&editor=".$itx['com-inner'][3]."&object=".urlencode($var1));
		}
		}
		else {
		
		$output = "<p>Inspection View: ".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=viewObjectDetail&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&editor=".$itx['com-inner'][3]."&object=".urlencode($var1));
	}
	writeResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(set my|set my avatar|set my character)+(\p{Zs}|\040)+(gender|sex)+(\p{Zs}|\040)+(to)+(\p{Zs}|\040)+(male|female)+/",$commandstring2)) {
	$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
	$var1 = preg_replace("/(set my|set my avatar|set my character)+(\p{Zs}|\040)+(gender|sex)+(\p{Zs}|\040)+(to)+(\p{Zs}|\040)+/","",$commandstring2);
	if (file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=setAvatarGender&uuid=".$itx['com-inner'][3]."&gender=".$var1) == "success") {
	$output = "<p>Appearance: Your avatar's gender has been set to ".$var1;
	}
	else {
	$output = "<p>Appearance: Your avatar's gender could not be changed.";
	}
	writeResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(look at|examine)+(\p{Zs}|\040)+(\w)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$var1 = preg_replace("/(look at|examine)+(\p{Zs}|\040)+/","",$commandstring2);
		$array3 = explode(" ",$var1);
		
		if((!isset($array3[2])) and (isset($array3[1]))) {
		$itx['com-inner'][6] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$array3[0]."&lastname=".$array3[1]);
		if ($itx['com-inner'][6] != "fail") {
		$itx['com-inner'][7] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][6]);
		$itx['com-inner'][8] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][7]);
		$array4 = splitData($itx['com-inner'][8]);
		$array5 = splitData(file_get_contents("http://".$array4[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][6]));
			if(($array5[0] == $array2[0]) and ($array5[1] == $array2[1])) {
			
			$itx['com-inner'][9] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getHeartbeat&uuid=".$itx['com-inner'][6]);
				if($itx['com-inner'][9] > (time() - 100)) {
				$output = "<p>Appearance: You see a ".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=viewAvatar&uuid=".$itx['com-inner'][6]);
				}
				else {
				$output = "<p>Scene: You don't see ".$array3[0]." ".$array3[1]." here at this time.";
				}
			}
			else {
				$output = "<p>Scene: You don't see ".$array3[0]." ".$array3[1]." here at this time.";
			}
		}
		else {
		$output = "<p>Inspection View: ".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=viewObject&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&editor=".$itx['com-inner'][3]."&object=".urlencode($var1));
		}
		}
		else {
		
		$output = "<p>Inspection View: ".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=viewObject&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&editor=".$itx['com-inner'][3]."&object=".urlencode($var1));
	}
	writeResponseFile($itx['com-inner'][3], $output);
	}
	
	elseif (preg_match("/(pick up|take)+(\p{Zs}|\040)+(\w)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$var1 = preg_replace("/(pick up|take)+(\p{Zs}|\040)+/","",$commandstring2);
		$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getObject&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&editor=".$itx['com-inner'][3]."&object=".urlencode($var1))."</span>";
	writeResponseFile($itx['com-inner'][3], $output);
	}
	
	
	
	elseif (preg_match("/(drop|place|put)+(\p{Zs}|\040)+(\w)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$var1 = preg_replace("/(drop|place|put)+(\p{Zs}|\040)+/","",$commandstring2);
		$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=putObject&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&editor=".$itx['com-inner'][3]."&object=".urlencode($var1))."</span>";
	writeResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(shout:|yell:|scream:)+(\p{Zs}|\040|\w|\W)+/",$commandstring2)) {
	$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$array3 = explode(":",$commandstring2);
		
		if (trim($itx['user']['emoticons']) == "yes") {
		$var1 = urlencode(smiley(strip_tags($array3[1])));
}
else {
$var1 = urlencode(strip_tags($array3[1]));
}
		if(!isset($_SESSION['chatlastcheck'])) {$_SESSION['chatlastcheck'] = unixtime;}
		
		file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=setLocalChatYell&uuid=".$itx['com-inner'][4]."&user=".$itx['com-inner'][3]."&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']."&localX=".$array2[0]."&localY=".$array2[1]."&data=".$var1."&time=".$_SESSION['chatlastcheck']);
		$var3 = file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalChat&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&time=".$_SESSION['chatlastcheck']);
		if($var3 != "nodata") {

writeResponseFile($itx['com-inner'][3], $var3);
		}
		$_SESSION['chatlastcheck'] = unixtime;
	}
	elseif (preg_match("/(whisper:|quietly say:)+(\p{Zs}|\040|\w|\W)+/",$commandstring2)) {
	$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$array3 = explode(":",$commandstring2);
if (trim($itx['user']['emoticons']) == "yes") {
		$var1 = urlencode(smiley(strip_tags($array3[1])));
}
else {
$var1 = urlencode(strip_tags($array3[1]));
}
		if(!isset($_SESSION['chatlastcheck'])) {$_SESSION['chatlastcheck'] = unixtime;}
		
		file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=setLocalChatWhisper&uuid=".$itx['com-inner'][4]."&user=".$itx['com-inner'][3]."&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']."&localX=".$array2[0]."&localY=".$array2[1]."&data=".$var1."&time=".$_SESSION['chatlastcheck']);
		$var3 = file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalChat&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&time=".$_SESSION['chatlastcheck']);
		if($var3 != "nodata") {

writeResponseFile($itx['com-inner'][3], $var3);

		}
		$_SESSION['chatlastcheck'] = unixtime;
	}
	elseif ($output == "") {
	$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
if (trim($itx['user']['emoticons']) == "yes") {		
$var1 = urlencode(smiley(strip_tags($commandstring)));
}
else {
$var1 = urlencode(strip_tags($commandstring));
}
		if(!isset($_SESSION['chatlastcheck'])) {$_SESSION['chatlastcheck'] = unixtime;}
		
		file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=setLocalChat&uuid=".$itx['com-inner'][4]."&user=".$itx['com-inner'][3]."&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']."&localX=".$array2[0]."&localY=".$array2[1]."&data=".$var1."&time=".$_SESSION['chatlastcheck']);
		$var3 = file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalChat&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&time=".$_SESSION['chatlastcheck']);
		if($var3 != "nodata") {

		
writeResponseFile($itx['com-inner'][3], $var3);

		}
		$_SESSION['chatlastcheck'] = unixtime;
	}
	return TRUE;
	
}
?>
